package com.sunma.repair.service.impl;

import java.util.List;

import com.sunma.common.exception.ServiceException;
import com.sunma.common.utils.DateUtils;
import com.sunma.common.utils.StringUtils;
import com.sunma.framework.aspectj.DataSourceAspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sunma.repair.mapper.AssetsRepairMapper;
import com.sunma.repair.domain.AssetsRepair;
import com.sunma.repair.service.IAssetsRepairService;

/**
 * 资产报修Service业务层处理
 * 
 * @author sunma
 * @date 2024-07-12
 */
@Service
public class AssetsRepairServiceImpl implements IAssetsRepairService 
{
    @Autowired
    private AssetsRepairMapper assetsRepairMapper;

    /**
     * 查询资产报修
     * 
     * @param id 资产报修主键
     * @return 资产报修
     */
    @Override
    public AssetsRepair selectAssetsRepairById(Long id)
    {
        return assetsRepairMapper.selectAssetsRepairById(id);
    }

    /**
     * 查询资产报修列表
     * 
     * @param assetsRepair 资产报修
     * @return 资产报修
     */
    @Override
    public List<AssetsRepair> selectAssetsRepairList(AssetsRepair assetsRepair)
    {
        return assetsRepairMapper.selectAssetsRepairList(assetsRepair);
    }

    /**
     * 新增资产报修
     * 
     * @param assetsRepair 资产报修
     * @return 结果
     */
    @Override
    public int insertAssetsRepair(AssetsRepair assetsRepair)
    {
        AssetsRepair selectAssetsRepairById = assetsRepairMapper.selectAssetsRepairByReceiveId(assetsRepair.getReceiveId());
        if (selectAssetsRepairById != null){
            throw new ServiceException("该资产已报修");
        }
        assetsRepair.setDate(DateUtils.getNowDate());
        assetsRepair.setAssetsId(assetsRepair.getAssetsId());
        assetsRepair.setReceiveId(assetsRepair.getReceiveId());

        return assetsRepairMapper.insertAssetsRepair(assetsRepair);
    }

    /**
     * 修改资产报修
     * 
     * @param assetsRepair 资产报修
     * @return 结果
     */
    @Override
    public int updateAssetsRepair(AssetsRepair assetsRepair)
    {
        return assetsRepairMapper.updateAssetsRepair(assetsRepair);
    }

    /**
     * 批量删除资产报修
     * 
     * @param ids 需要删除的资产报修主键
     * @return 结果
     */
    @Override
    public int deleteAssetsRepairByIds(Long[] ids)
    {
        return assetsRepairMapper.deleteAssetsRepairByIds(ids);
    }

    /**
     * 删除资产报修信息
     * 
     * @param id 资产报修主键
     * @return 结果
     */
    @Override
    public int deleteAssetsRepairById(Long id)
    {
        return assetsRepairMapper.deleteAssetsRepairById(id);
    }
}
